-
Notifications
You must be signed in to change notification settings - Fork 193
Ignore primary key, foreign key and unique constraints for DDL generation #541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
e3ace59
to
66c389f
Compare
66c389f
to
f7d4d73
Compare
trino/sqlalchemy/compiler.py
Outdated
def visit_foreign_key_constraint(self, constraint, **kw): | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than silently ignoring constraints, maybe we should raise an explicit error indicating that these constraints are not supported in Trino:
def visit_foreign_key_constraint(self, constraint, **kw): | |
return None | |
from sqlalchemy.exc import CompileError | |
... | |
def visit_foreign_key_constraint(self, constraint, **kw): | |
raise CompileError("Trino does not support FOREIGN KEY constraints.") |
Or at least we could add a warning to make it clearer that the constraint is being ignored:
def visit_foreign_key_constraint(self, constraint, **kw): | |
return None | |
import warnings | |
from sqlalchemy.exc import SAWarning | |
... | |
def visit_foreign_key_constraint(self, constraint, **kw): | |
warnings.warn("Trino does not support FOREIGN KEY constraints. Constraint will be ignored.", SAWarning) | |
return None |
@willmostly @hashhar WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@willmostly PTAL.
this would enable using sqlalchemy ORM-like features, being aware that PK and FK are not enforced. Right now it's not otherwise possible.
|
@hashhar @willmostly I added warnings about unsupported constraints, PTAL |
Description
Define custom visitors in
TrinoDDLCompiler
to ignore constraints.Non-technical explanation
By default, SQLAlchemy adds
PRIMARY KEY
and other constraint keywords to table creation DDL when these constraints are defined on aTable
or class derived from declarative base. Since Trino does not support constraints, this results in invalid SQL. With this change the trino sqlalchemy extension now ignores primary key, foreign key and unique constraints when generating table DDL.Release notes
( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(x) Release notes are required, with the following suggested text:
* ignore constraints for table DDL generation